package com.tiancheng.trade.order.controller.admin;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.utils.JsonUtil;
import com.tiancheng.trade.order.service.SubOrderService;
import com.tiancheng.trade.order.vo.admin.QuerySubOrderVO;
import com.tiancheng.trade.order.vo.admin.res.SubOrderDetailResVO;
import com.tiancheng.trade.order.vo.admin.res.SubOrderResVO;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/admin/order/subOrder")
@Slf4j
@Validated
public class SubOrderAdminController {

    @Autowired
    private SubOrderService subOrderService;

    /***
     * @description: 子订单查询
     * @param subOrderVO
     * @return:
     * @date: 2024-02-22 17:00
     * @auther: liudong
     *
     */
    @GetMapping("/findSubOrderList")
    public Result<?> findSubOrderList(QuerySubOrderVO subOrderVO) {
        log.info("子订单查询 para:{}", JsonUtil.toJsonString(subOrderVO));
        PageInfo<SubOrderResVO> pageInfo = subOrderService.querySubOrderList(subOrderVO);
        log.info("管理端子订单查询 返回data：{}", JsonUtil.toJsonString(pageInfo));
        return Result.success(pageInfo);
    }

    /**
     * 子订单导出
     */
    @PostMapping("/exportOrderList")
    public void exportOrderList(@RequestBody QuerySubOrderVO subOrderVO, HttpServletResponse response) throws IOException {
        subOrderService.exportOrderList(subOrderVO, response);
    }

    /**
     * 功能描述: 子订单查询详情
     *
     * @param:subOrderId
     * @return:
     * @auther: LiuDong
     * @date: 10:15 2024/4/2
     */
    @GetMapping("/{subOrderId}")
    public Result findSubOrderDetailBySubOrderId(@PathVariable String subOrderId) {
        SubOrderDetailResVO parametersVO = subOrderService.findSubOrderBySubId(subOrderId);
        return Result.success(parametersVO);
    }

}
